package com.renge.ossservice.utils;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;

import java.io.InputStream;

public class OssUploadUtils {
    public  String endpoint  ;
    public  String accessKeyId ;
    public  String accessKeySecret;
    public  String bucketName ;
    OSS ossClient=null;
    public OssUploadUtils(String endpoint,String accessKeyId,String accessKeySecret,String bucketName){
        this.endpoint=endpoint;
        this.accessKeyId=accessKeyId;
        this.accessKeySecret=accessKeySecret;
        this.bucketName=bucketName;
        // 创建OSSClient实例。
        ossClient = new OSSClientBuilder().build(this.endpoint, this.accessKeyId,this.accessKeySecret);
    }
    public void  uplpad(InputStream inputStream,String fileName) throws Exception{

        // 填写Bucket名称和Object完整路径。Object完整路径中不能包含Bucket名称。
        ossClient.putObject(bucketName, fileName, inputStream);

    }
    public void  close(){
        // 关闭OSSClient。
        ossClient.shutdown();
    }

}
